<?php

namespace app\common\validate;

use think\Validate;

class Address extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
    	'name' => 'require',
	    'mobile' => 'checkMobile',
	    'province_id' => 'require',
	    'city_id' => 'require',
	    'area_id' => 'require',
	    'address' => 'require'
    ];
    /**
     * 提示消息
     */
    protected $message = [
    	'name' => '收货人姓名不能为空',
	    'mobile' => '手机号不能为空',
	    'province_id' => '省份不能为空',
	    'city_id' => '城市不能为空',
	    'area_id' => '区域不能为空',
	    'address' => '详细地址不能为空',
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => [],
        'edit' => [],
    ];
    
    protected function checkMobile($value) {
    	$preg = '/^1\d{10}$/';
    	if(!preg_match($preg, trim($value))) {
    		return '手机号码格式不正确';
	    }
    	
    	return true;
    }
    
}
